import request from '@/utils/request'
import { CHECC_API_BASE_DATA } from '@/constants/proxy'

// 获取涵洞列表
export function requestCulvertList(params: any,data:any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bdCulvertIn/page`,
    method: 'post', 
    data:data,
    params,
  })
}

// 保存涵洞信息
export function saveCulvert(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bdCulvertIn`,
    method: 'post',
    data
  })
}

// 删除涵洞信息
export function delCulvert(data: any): Promise<any> {
  const str = data.culverInIds.reduce((rst, cur) => {
    if(rst === '?'){
      rst += `culverInIds=${cur}`
    }else{
      rst += `&culverInIds=${cur}`
    }
    return rst
  }, '?')
  return request({
    url: CHECC_API_BASE_DATA + `/bdCulvertIn/delete` + str,
    method: 'get',
    data
  })
}

// 更新涵洞信息
export function updateCulvert(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bdCulvertIn/update`,
    method: 'post',
    data
  })
}
// 通过id查询数据
export function obtainCulvert(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bdCulvertIn/${data}`,
    method: 'get',
  })
}

// 锁定/解锁
export function culvertLock(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bdCulvertIn/lock`,
    method: 'post',
    data
  })
}

// 导出涵洞信息
export function exportCulvertRecordsRequest(): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bdCulvertIn/export`,
    method: 'post',
    data: {}
  })
}

/* InConstruction子表 */
// 获取
export function getCulvertInConstruction(data): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-culvert-in-construction/page`,
    method: 'post',
    data: data.data || {},
    params: data.params
  })
}

export function addCulvertInConstruction(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-culvert-in-construction`,
    method: 'post',
    data
  })
}

export function updateCulvertInConstruction(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-culvert-in-construction`,
    method: 'put',
    data
  })
}

export function delCulvertInConstruction(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-culvert-in-construction`,
    method: 'delete',
    data
  })
}

/** in-evaluation子表 */
export function getCulvertInEvaluation(data): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-culvert-in-evaluation/page`,
    method: 'post',
    data: data.data || {},
    params: data.params
  })
}

export function addCulvertInEvaluation(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-culvert-in-evaluation`,
    method: 'post',
    data
  })
}

export function updateCulvertInEvaluation(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-culvert-in-evaluation`,
    method: 'put',
    data
  })
}

export function delCulvertInEvaluation(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-culvert-in-evaluation`,
    method: 'delete',
    data
  })
}
//获取涵洞概览数据
export function getCulvertOverview(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bdCulvertIn/overview`,
    method: 'post',
    data
  })
}